<?php include "./pc/view/header.inc.htm"; ?>

<div class="panel_body margin">
	<div class="body">
		<form method="POST" id="thread_create_form" action="thread-create.htm">
			<p class="margin"><span id="forum_select"></span> <input type="text" placeholder="标题" name="subject" style="width: 700px;"></p>
			<p class="margin"><textarea id="message" name="message" placeholder="内容" style="width: 100%; height: 500px;"></textarea></p>
			<?php if($conf['seo_url_rewrite'] && $group['allowcustomurl']) { ?>
			<p class="margin"><input type="text" placeholder="自定义 URL：just-like-this-why-sky-is-blue" name="seo_url" style="width: 100%;"></p>
			<?php } ?>
			<dl class="row margin">
				<dt>
					<button type="submit" loading-text="正在提交..." class="big blue" style="width: 208px;">发帖</button>
				</dt>
				<dd class="right">
				</dd>
			</dl>
		</form>
	</div>
</div>

<script id="script_data">
var fid = <?php echo $fid; ?>;// 当前激活的 fid
</script>

<?php include "./pc/view/footer.inc.htm"; ?>

<link rel="stylesheet" type="text/css" href="xneditor/editor.css" />

<script src="xiunoui/async.js"></script>
<script src="xiunoui/upload.js"></script>
<script src="xneditor/editor.js"></script>
<script>

var editor = new $.XNEditor({textarea: 'message', image_upload_url:'post-upload-1.htm', image_upload_width: <?php echo $conf['upload_image_width']; ?>, file_upload_url:'post-upload-0.htm'});
var jform = $('#thread_create_form');
var jinput = jform.find('input');
var jsubject = jinput.filter('[name="subject"]').focus();
var jmessage = $('#message');
var jseo_url = jform.find('input[name="seo_url"]');
var jsubmit = jform.find('button').filter('[type="submit"]');

// 选择论坛
var jforum_select = $('#forum_select');
var forumarr = <?php echo $forumarr; ?>;
var s = '<select name="fid">'; 
for(k in forumarr) s += '<option value="'+k+'">'+forumarr[k]+'</option>';
s += '</select>';
var jselect = jforum_select.html(s).find('select');
jselect.checked(fid);

jform.off('submit').on('submit', function() {
	if(!jsubject.val()) {
		jsubject.popover('请输入标题！').focus();
		return false;
	}
	if(!jmessage.val()) {
		editor.jeditor.popover('请输入内容');
		editor.focus();
		return false;
	}
	jsubmit.button('loading');
	var postdata = jform.serializeObj();
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.button('发帖成功');
			var fid = $('select[name="fid"]').checked();
			setTimeout(function() {editor.clear(); window.location='forum-'+fid+'.htm';}, 1000);
			return;
		} else if(code == 1) {
			jsubject.popover(message).focus();
		} else if(code == 2) {
			jmessage.popover(message).focus();
		} else if(code == 3) {
			jselect.popover(message).focus();
		} else if(code == 4) {
			jseo_url.popover(message).focus();
		} else {
			$.alert(message);
		}
		jsubmit.button('reset');
	});
	return false;
});

// 快捷键回复
jform.keyup(function(e) {
	if((e.ctrlKey && (e.which == 13 || e.which == 10)) || (e.altKey && e.which == 83)) {
		jsubmit.trigger('click');
		return false;
	}
});

</script>